package com.study.order.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;

/**
 * 模拟JDK动态代理
 *
 * @author yuanqiji
 * @date 2022/08/16
 **/
public class $Proxy0 extends Proxy implements Foo {

	protected $Proxy0(InvocationHandler h) {
		super(h);
	}


	@Override
	public void food() {
		try {
			this.h.invoke(this, food, null);
		} catch (Throwable e) {
			throw new UndeclaredThrowableException(e);
		}
	}

	@Override
	public int bar() {
		try {
			Object result = this.h.invoke(this, bar, new Object[0]);
			return (int) result;
		} catch (Throwable e) {
			throw new UndeclaredThrowableException(e);
		}
	}

	static Method food;
	static Method bar;

	static {
		try {
			food = Foo.class.getMethod("food");
			bar = Foo.class.getMethod("bar");
		} catch (NoSuchMethodException e) {
			throw new NoSuchMethodError(e.getMessage());
		}
	}
}
